quit while (someone) is ahead

Translations
s'arrêter tant qu'on a encore l'avantage
Definitions
To stop doing something before it becomes detrimental or before one loses the advantage they currently have.